/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package course.entities;

import java.io.Serializable;
import java.util.List;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;

/**
 *
 * @author def
 */
@Entity
@Table(name = "groups")
@SequenceGenerator(sequenceName = "global_seq", name = "global_seq")
@NamedQueries({@NamedQuery(name = "UserGroup.findAll", query = "SELECT ug FROM UserGroup ug")})
public class UserGroup implements Serializable {

    private static final long serialVersionUID = -23475342676583L;

    @Id
    @GeneratedValue(strategy = GenerationType.SEQUENCE)
    @Column(name = "group_id")
    private long id;
    
    @Column(name = "group_name")
    private String groupName;

    @ManyToMany
    @JoinTable(
        name = "users_groups",
        joinColumns = {@JoinColumn(name = "group_name", referencedColumnName = "group_name")},
        inverseJoinColumns = {@JoinColumn(name = "user_name", referencedColumnName = "user_name")}
    )
    private List<User> users;

    public UserGroup() {
    }

    public long getId() {
        return id;
    }

    public void setId(long id) {
        this.id = id;
    }

    public String getGroupName() {
        return groupName;
    }

    public void setGroupName(String groupName) {
        this.groupName = groupName;
    }

    public List<User> getUsers() {
        return users;
    }

    public void setUsers(List<User> users) {
        this.users = users;
    }

    @Override
    public String toString() {
        return "UserGroup{" + "id=" + id + ", groupName=" + groupName + '}';
    }
    
}
